﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

using QLCHBANGIAY.COMMON;
using System.Web.Routing;


namespace QuanLyBanGiay
{
    public class Global : System.Web.HttpApplication
    {

        public static string LangDefault = "";
        public static CookieClass Cookie = new CookieClass();
        /// <summary>
        /// Extension of page file
        /// </summary>
        public static string FileExtension = "";

        void RegisterRoutes(RouteCollection routes)
        {
            //trang index
            RouteTable.Routes.MapPageRoute("Productspage1", "index.htm/page={currentpage2}", "~/index.aspx");
            //hien thi san pham
            RouteTable.Routes.MapPageRoute("Products", "{title}.htm", "~/index.aspx");

            RouteTable.Routes.MapPageRoute("sanpham", "{title}.htm", "~/phanloaisanpham.aspx");


            //
            //shoppingcart
            //
            RouteTable.Routes.MapPageRoute("indexcart", "index.htm/productid={cart}", "~/index.aspx");
        }
        void Application_Start(object sender, EventArgs e)
        {

            //LangDefault = LanguageService.Language_GetByDefault();
            LangDefault = "vi";
            //FileExtension = GlobalClass.GetAppSettingKey("FileExtension");
            RegisterRoutes(RouteTable.Routes);
            // Code that runs on application startup
            Application["online"] = 0;
            Application["soluottruycap"] = 0;
        }

        void Application_End(object sender, EventArgs e)
        {
            //  Code that runs on application shutdown

        }

        void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs

        }

        void Session_Start(object sender, EventArgs e)
        {
            // Code that runs when a new session is started
            if (Session["Lang"] == null)
            {
                Cookie.SetCookie("Lang", LangDefault);
                Session["Lang"] = LangDefault;
            }
            // Code that runs when a new session is started
            Application["online"] = int.Parse(Application["online"].ToString()) + 1;
            // Application["songuoionline"] = int.Parse(Application["soluottruycap"].ToString()) + 1;
            common.Update_useronline();
        }
        void Session_End(object sender, EventArgs e)
        {
            // Code that runs when a session ends. 
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer 
            // or SQLServer, the event is not raised.
            if (Session["Lang"] == null)
            {
                Session["Lang"] = GetLang();
            }
            Application["online"] = int.Parse(Application["online"].ToString()) - 1;
            // Code that runs when a session ends.
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer
            // or SQLServer, the event is not raised.
            common.userofline();

        }
        public static string GetLang()
        {
            return StringClass.Check(Cookie.GetCookie("Lang")) ? Cookie.GetCookie("Lang") : "";
        }
        public static string GetLangAdm()
        {

            return StringClass.Check(Cookie.GetCookie("LangAdm")) ? Cookie.GetCookie("LangAdm") : "";

        }

    }
}